# Maintainer: Anatol Pomozov
# Contributor: Alad Wenter <alad (at) archlinux.info>
# Contributor: Jochen Schalanda <jochen+aur (at) schalanda.name>
# Contributor: C. Dominik Bódi <dominik.bodi@gmx.de>
# Contributor: Pierre Carrier <pierre@spotify.com>
# Contributor: Thomas Dziedzic <gostrc (at) gmail>
# Contributor: Chris Giles <Chris.G.27 (at) Gmail.com>
# Contributor: seblu <seblu+arch (at) seblu.net>
# Contributor: squiddo <squiddo (at) intheocean.net>
# Contributor: dront78 <dront78 (at) gmail.com>
# Contributor: hugelgupf <ckoch (at) cs.nmt.edu>

pkgname=dpkg
pkgver=1.22.0
pkgrel=1
pkgdesc='The Debian Package Manager tools'
arch=('loong64' 'x86_64')
url="https://tracker.debian.org/pkg/dpkg"
license=('GPL')
options=('emptydirs')
depends=('xz' 'zlib' 'bzip2' 'zstd' 'perl' 'libmd')
makedepends=('perl-io-string' 'perl-timedate' 'git')
checkdepends=('perl-io-string' 'perl-test-pod')
install=dpkg.install
source=(https://salsa.debian.org/dpkg-team/dpkg/-/archive/$pkgver/dpkg-$pkgver.tar.bz2
        origin.archlinux)
sha256sums=('1151887ea16026ff7706f71efd336fe79c60a79740cd5c38aafcee9d40add432'
            '193ac1929ea93157c0173db3c871d2f7fe53385391f48078190b03904c5b1f2d')

prepare() {
    cd dpkg-$pkgver
    echo "$pkgver" > .dist-version
    ./autogen
}

build() {
    cd dpkg-$pkgver
    CFLAGS+=' -ffat-lto-objects' \
    ./configure --prefix=/usr \
        --sysconfdir=/etc \
        --localstatedir=/var \
        --sbindir=/usr/bin \
        --libexecdir=/usr/lib \
        --disable-start-stop-daemon
    make
}

check() {
    cd dpkg-$pkgver
    # make check
}

package() {
    cd dpkg-$pkgver
    make DESTDIR="$pkgdir" install
    install -Dm644 ../origin.archlinux "$pkgdir"/etc/dpkg/origins/archlinux
    ln -sf archlinux "$pkgdir"/etc/dpkg/origins/default

    install -d "$pkgdir/var/dpkg"/updates/
    touch "$pkgdir/var/lib/dpkg"/{status,available}
}
